<?php

namespace app\admin\validate;

use think\Validate;

class SaleOrder extends Validate
{
    /**
     * 验证规则
     */
    protected $rule = [
        'manufacturer_id'       => 'require|integer|gt:0',
        'customer_id'           => 'require|integer|gt:0',
        'order_date'            => 'require|date',
        'total_weight'          => 'float|egt:0',
        'total_amount'          => 'require|float|gt:0',
        'discount_amount'       => 'float|egt:0',
        'total_purchase_price'  => 'require|float|gt:0',
        'customer_payment'      => 'float|egt:0',
        'manufacturer_payment'  => 'float|egt:0',
        'notes'                 => 'max:255',
    ];
    
    /**
     * 提示消息
     */
    protected $message = [
        'manufacturer_id.require'   => '厂家不能为空',
        'manufacturer_id.integer'   => '厂家ID必须是整数',
        'manufacturer_id.gt'        => '厂家ID必须大于0',
        'customer_id.require'       => '客户不能为空',
        'customer_id.integer'       => '客户ID必须是整数',
        'customer_id.gt'            => '客户ID必须大于0',
        'order_date.require'        => '下单时间不能为空',
        'order_date.date'           => '下单时间格式不正确',
        'total_weight.float'        => '总重量必须是数字',
        'total_weight.egt'          => '总重量必须大于或等于0',
        'total_amount.require'      => '总金额不能为空',
        'total_amount.float'        => '总金额必须是数字',
        'total_amount.gt'           => '总金额必须大于0',
        'discount_amount.float'     => '优惠金额必须是数字',
        'discount_amount.egt'       => '优惠金额必须大于或等于0',
        'total_purchase_price.require' => '总进货价不能为空',
        'total_purchase_price.float'   => '总进货价必须是数字',
        'total_purchase_price.gt'      => '总进货价必须大于0',
        'customer_payment.float'    => '客户付款金额必须是数字',
        'customer_payment.egt'      => '客户付款金额必须大于或等于0',
        'manufacturer_payment.float' => '付款给厂家金额必须是数字',
        'manufacturer_payment.egt'   => '付款给厂家金额必须大于或等于0',
        'notes.max'                 => '备注最多不能超过255个字符',
    ];
    
    /**
     * 验证场景
     */
    protected $scene = [
        'add'  => ['manufacturer_id', 'customer_id', 'order_date', 'total_weight', 'total_amount', 'discount_amount', 'total_purchase_price', 'customer_payment', 'manufacturer_payment', 'notes'],
        'edit' => ['manufacturer_id', 'customer_id', 'order_date', 'total_weight', 'total_amount', 'discount_amount', 'total_purchase_price', 'customer_payment', 'manufacturer_payment', 'notes'],
    ];
} 